﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

/// <summary>
/// TBBSForum 的摘要说明
/// </summary>
public class TBBSForum : TData
{
    const string CTableName = "t_bbs_forum";
    const string CKeyName = "forum_id";

    private string FForumID;
    private string FForumTID;
    private string FForumTitle;
    private string FForumContent;
    private string FForumAuthor;
    private DateTime FForumTime;
    private int FForumFlag;

    public TBBSForum()
    {
        FTableName = CTableName;
        FKeyName = CKeyName;
    }

    public TBBSForum(string ID)
    {
        FTableName = CTableName;
        FKeyName = CKeyName;
        FKeyValue = ID;
    }

    /// <summary>
    /// （静态）根据编号在数据库中删除记录。
    /// </summary>
    public static void DeleteByID(string ID)
    {
        TData.DeleteByID(ID, CTableName, CKeyName);
    }

    /// <summary>
    /// 在数据库中检索记录（已重写）。
    /// </summary>
    public override void Select()
    {
        string strSql = GetSelectString();
        TSqlDB oDB = new TSqlDB(strSql);
        if (!oDB.EOF)
        {
            FForumID = oDB["forum_id"].ToString();
            FForumTID = oDB["forum_tid"].ToString();
            FForumTitle = oDB["forum_title"].ToString();
            FForumContent = oDB["forum_content"].ToString();
            FForumAuthor = oDB["forum_author"].ToString();
            FForumTime = oDB["forum_time"].ToDateTime();
            FForumFlag = oDB["forum_flag"].ToInt();
        }
        oDB.Free();
    }

    /// <summary>
    /// （静态）改变状态,0=正常,1=隐藏。
    /// </summary>
    public static void ChgFlag(string ID, int iFlag)
    {
        string strSql = "update " + CTableName + " set forum_flag=" + iFlag.ToString() + " where " + CKeyName + "='" + ID + "'";
        TSqlDB.ExecuteNonQuery(strSql);
    }

    /// <summary>
    /// 在数据库中插入记录。
    /// </summary>
    public void Insert()
    {
        string ExSql = "newid(), '" + FForumTID + "','" + FForumTitle + "','" + FForumContent + "','" + FForumAuthor + "', getdate(),0";
        base.Insert(ExSql);
    }

    /// <summary>
    /// 在数据库中更新记录。
    /// </summary>
    public void Update()
    {
        string ExSql = "forum_title='" + FForumTitle + "', forum_content='" + FForumContent + "'";
        base.Update(ExSql);
    }

    public string ForumTID
    {
        get
        {
            return FForumTID;
        }
        set
        {
            FForumTID = value;
        }
    }

    public string ForumTitle
    {
        get
        {
            return FForumTitle;
        }
        set
        {
            FForumTitle = value;
        }
    }

    public string ForumContent
    {
        get
        {
            return FForumContent;
        }
        set
        {
            FForumContent = value;
        }
    }

    public string ForumAuthor
    {
        get
        {
            return FForumAuthor;
        }
        set
        {
            FForumAuthor = value;
        }
    }
}
